<?php
// $Id: agres_funcs.inc,v 1.1.2.3 2010/10/17 21:25:01 agill Exp $
/**
 * @file
 * helper functions. not only usefull for agreservations
 */

/**
  * in_multi_assoc_array: returns BOOLEAN.
  *
  * @author     Andreas Gill
  * @param      $needle zu suchender Wert.
  * @param      $array   zu durchsuchendes Array.
  * @return     TRUE oder FALSE
  */
    function in_multi_assoc_array($needle, $array)
    {
        foreach ($array as $element){
           if ($element == $needle) {
               return true;
           }else{
               if (is_array($element)){
                 if(in_multi_assoc_array($needle,$element)){
                     return true;
                 }
               }
           }
        }
        return false;
    }
    /**
  * _is_time_in_range: returns BOOLEAN.
  *
  * @author     Andreas Gill
  * @param      $timetocheck time to check.timestring'H:i'
  * @param      $rangelow lower end of timerange.timestring'H:i'
  * @param      hrangehigh higher end of timerange.timestring of form 'H:i'
  * @return     TRUE if in range or FALSE if not within range
  */
    function _is_time_in_range($timetocheck, $rangelow,$rangehigh){
      $strtimetocheck = date('H:i',strtotime($timetocheck));
       if ((strtotime($strtimetocheck) >= strtotime($rangelow))&&(strtotime($strtimetocheck) <= strtotime($rangehigh))) {        
          return TRUE;
       }
       else {
         return FALSE;
       }
    }

 /**
  * get_current_path: current url
  * from drupaluser dhaneshharidas 
  * from http://drupal.org/node/46088
  */
  function get_current_path() {
  $current_path = explode('=', drupal_get_destination());
  // Extracting URL from $current_path
  if (is_array($current_path) && count($current_path) >= 2) {
    if (trim($current_path[1]) != '') {
      $current_url_full = htmlspecialchars(urldecode($current_path[1]));
      // Removing query string
      $current_url_elements = explode('?', $current_url_full);
      if (is_array($current_url_elements)) {
        return trim($current_url_elements[0]);
      } else {
        return trim($current_url_elements);
      }
    } else {
      return $_REQUEST['q'];
    }
  }
}